const express = require('express')
const db = require('../db/index')

exports.getInfo = (req, res)=>{
  const id = req.user.id
  sql = 'select id, username, nickname, email, user_pic from ev_users where id=?'
  db.query(sql, id, (err, result) => {
    if (err) return res.cc(err)
    if (result.length !== 1) return res.cc('获取用户信息失败!')
    res.send({
      status: 0,
      message: '获取用户信息成功!',
      data: result[0]
    })
  })
}

exports.updataInfo = (req,res)=>{
  /*
    id=36119
    nickname=%E6%9D%9C
    email=3105179409%40qq.com
    实现更新用户基本信息的功能
  */
  const sql = 'updata ev_users set ? where id = ?'
  db.query(sql,[req.body,req.body.id],(err,result)=>{
    if(err) return res.cc(err)
    res.send(result)
  })
}